class Solution:
    def longestCommonSubsequence(self, text1: str, text2: str) -> int:
        m = len(text1)
        n = len(text2)
        if not m or not n:
            return 0
        dp = [[0] * (n + 1) for _ in range(m + 1)]
        print(dp)
        for i in range(1, m + 1):
            for j in range(1, n + 1):
                print(i, j)
                if text1[i - 1] == text2[j - 1]:
                    # if dp[i - 1][j]:
                    dp[i][j] = dp[i - 1][j - 1] + 1
                else:
                    dp[i][j] = max(dp[i][j - 1], dp[i - 1][j])
        print(dp)
        return dp[-1][-1]


if __name__ == "__main__":
    res = Solution().longestCommonSubsequence("abcbcba", "bbbbba")
    print(res)
